use std::io::{Result};

use super::types::umutex::{Umutex,ScopedLock};
use super::types::meta::{Meta};
use super::types::mbox::MBox;
pub struct Exchange<T> where T:Copy {
    data : T, 
    um : Umutex,
}
impl<T> Exchange<T> where T:Copy {
    pub fn from_data(&mut self, d:&Exchange<T>) {
        let _l = ScopedLock::new(&mut self.um);
        self.data = d.data;
    }
    pub fn to_data(&mut self, d:&mut Exchange<T>) {
        let _l = ScopedLock::new(&mut self.um);
        d.data = self.data;
    }
    pub fn attach(m:&Meta,o:usize) -> Result<MBox<T>> {
        m.attach::<T>(o)
    } 
}